#include "catalog.h"

//
// Destroys a relation. It performs the following steps:
//
// 	removes the catalog entry for the relation
// 	destroys the heap file containing the tuples in the relation
//
// Returns:
// 	OK on success
// 	error code otherwise
const Status RelCatalog::destroyRel(const string & relation)
{
  Status status;

  if (relation.empty() || 
      relation == string(RELCATNAME) || 
      relation == string(ATTRCATNAME))
    return BADCATPARM;

  status = attrCat->dropRelation(relation);
  if (status != OK) return status;

  status = relCat->removeInfo(relation);
  if (status != OK) return status;
  
  status = destroyHeapFile(relation);
  return status;

}


//
// Drops a relation. It performs the following steps:
//
// 	removes the catalog entries for the relation
//
// Returns:
// 	OK on success
// 	error code otherwise
//

const Status AttrCatalog::dropRelation(const string & relation)
{
  Status status;
  AttrDesc *attrs;
  int attrCnt, i;

  if (relation.empty()) return BADCATPARM;
  
 
  status = getRelInfo(relation,attrCnt, attrs);
  if (status != OK) return status;
  // remove tuple from attributes catalog
  for (i = 0; i < attrCnt; i++)
  {
     
    status = removeInfo(relation, attrs[i].attrName);
    if (status != OK) return status;
  
  }
  // return OK once all the attr are droped from catalog
  return status;
  
  

}


